package com.gxa.controller.activities;


import com.gxa.common.R.ResponseData;
import com.gxa.pojo.Activity;
import com.gxa.pojo.Jianli;
import com.gxa.service.activities.Activities;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


@Api(value = "相关活动ActivitiesController",tags = "相关活动API")
@Controller
@RequiresPermissions({"相关活动"})
@RequestMapping("/activities")
public class ActivitiesController {

    @Autowired
    private Activities activities;

    /**
     * 在活动表中活动名插入图片
     * @param activityName
     * @param file
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/insertActivity",method = RequestMethod.POST)
    @ApiOperation(value = "添加活动",notes = "添加活动界面",httpMethod = "post", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "activityName", value = "活动名称", required = true, dataType = "String"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })

    public ResponseData insertActivity(@RequestParam String activityName,
                                       @RequestParam MultipartFile file){

        return activities.insertActivity(activityName,file);
    }

    /**
     *
     * @param currentPage           当前页码数
     * @param pageSize              每页显示记录数
     * @param activityName          活动名称
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/selectActivity",method = RequestMethod.GET)
    @ApiOperation(value = "分页+模糊查询所有活动",notes = "提交页数和每页显示条数，活动名称关键字查询",httpMethod = "get", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "每页显示条数", required = true, dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "当前页数", required = true, dataType = "int"),
            @ApiImplicitParam(name = "activityName", value = "活动姓名模糊关键字", required = true, dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResponseData selectActivity(@RequestParam int currentPage,
                                       @RequestParam int pageSize,
                                       @RequestParam String activityName){
        ResponseData responseData = new ResponseData();
//        responseData.setCode(200);
//        responseData.setMsg("查询活动成功");
//        Map map =new HashMap();
//        map.put("activityName","你画我猜");
//        map.put("activityPhoto","图片地址");
//        responseData.setData(map);
        return activities.selectActivity(currentPage,pageSize,activityName);
    }

    /**
     * 修改活动
     * @param activityName
     * @param file
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/updateActivity",method = RequestMethod.POST)
    @ApiOperation(value = "修改活动",notes = "修改活动界面",httpMethod = "post", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "activityName", value = "活动名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "id", value = "活动id", required = true, dataType = "int"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResponseData updateActivity(@RequestParam String activityName,
                                       @RequestParam MultipartFile file,
                                       @RequestParam int id){
        return activities.updateActivity(activityName,file,id);
    }


    @ResponseBody
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ApiOperation(value = "删除活动",notes = "删除活动界面",httpMethod = "post", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "活动id", required = true, dataType = "int"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResponseData delete(@RequestParam int id){
        return activities.delete(id);
    }

    @ResponseBody
    @RequestMapping(value = "/selectByTheme",method = RequestMethod.GET)
    @ApiOperation(value = "分页+模糊查询所有活动内容",notes = "提交页数和每页显示条数，活动主题关键字查询",httpMethod = "get", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "每页显示条数", required = true, dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "当前页数", required = true, dataType = "int"),
            @ApiImplicitParam(name = "theme", value = "活动姓名模糊关键字", required = true, dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResponseData selectByTheme(@RequestParam Integer currentPage,
                               @RequestParam Integer pageSize,
                               @RequestParam String theme){

        return activities.selectByTheme(currentPage,pageSize,theme);
    }

    @ResponseBody
    @RequestMapping(value = "/insertById",method = RequestMethod.POST)
    @ApiOperation(value = "新增活动内容",notes = "新增活动内容界面",httpMethod = "post", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "活动名称id", required = true, dataType = "int"),
            @ApiImplicitParam(name = "theme", value = "活动主题", required = true, dataType = "String"),
            @ApiImplicitParam(name = "time", value = "活动时间", required = true, dataType = "String"),
            @ApiImplicitParam(name = "content", value = "活动内容", required = true, dataType = "int")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResponseData insertById(@RequestParam int id,
                               @RequestParam String theme,
                               @RequestParam String time,
                               @RequestParam String content){
        return activities.insertById(id,theme,time,content);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteById",method = RequestMethod.POST)
    @ApiOperation(value = "删除活动内容",notes = "删除活动内容界面",httpMethod = "post", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "活动内容id", required = true, dataType = "int")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResponseData deleteById(@RequestParam int id){
        return activities.deleteById(id);
    }

//    @ResponseBody
//    @RequestMapping(value = "/updatePhoto",method = RequestMethod.POST)
//    @ApiResponses({
//            @ApiResponse(code=200,message="请求成功"),
//            @ApiResponse(code=404,message="找不到页面"),
//            @ApiResponse(code=500,message="后台服务错误")
//    })
//    public ResponseData updatePhoto(@RequestParam MultipartFile file)throws IOException{
//        ResponseData responseData = new ResponseData();
//        activities.updatePhoto(file);
//        return responseData;
//    }

    @ResponseBody
    @RequestMapping(value = "/updateContent",method = RequestMethod.POST)
    @ApiOperation(value = "修改活动内容",notes = "修改活动内容",httpMethod = "post", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "theme", value = "活动主题", required = true, dataType = "String"),
            @ApiImplicitParam(name = "id", value = "活动内容id", required = true, dataType = "int"),
            @ApiImplicitParam(name = "time", value = "活动时间", required = true, dataType = "String"),
            @ApiImplicitParam(name = "content", value = "活动内容", required = true, dataType = "int")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResponseData updateContent(@RequestParam int id,
                                    @RequestParam String theme,
                                    @RequestParam String time,
                                    @RequestParam String content){

        return activities.updateContent(id,theme,time,content);
    }



}
